package DDL;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

import java.util.List;


public class GetTableMessage { //获取一张表中所有字段名称
	@SuppressWarnings("finally")
public static boolean getTableMessage(String dataBaseName,String tableName,List<String> attrList){//列出制定表的所有字段名称
	File tableFile = new File("D:\\database\\" + dataBaseName + "\\"   
			+ tableName + ".dbf");  //先判断表是否存在
	if (!tableFile.exists()) {
		System.out.println("没有这张表");
		return false;
	}
	FileReader fileReader = null;
	BufferedReader bufferReader = null;

	try {
		fileReader = new FileReader(tableFile);
		bufferReader = new BufferedReader(fileReader);
		String tempString = null;
		try {
			String[] tempStringList;
			while ((tempString = bufferReader.readLine()) != null) { //逐行读取文件内容
				tempStringList = tempString.split(",");// 每行数据按逗号分隔到数组tempStringList
				attrList.add(tempStringList[0].trim());	//将数组tempStringList中第一个元素即字段名称加入attrList表中
			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();    //打印异常
			System.out.println("读文件时异常");
			return false;
		}
	} catch (FileNotFoundException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
		System.out.println("文件打开异常");
		return false;
	} finally {
		try {
			bufferReader.close();
			fileReader.close();
			return true;
		} catch (IOException e) {
			e.printStackTrace();
			System.out.println("关闭文件异常");
			return false;
		}
	}
}

}

	


